home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / toolkit / saveatt.asm < prev    next >
Assembly Source File  |  1991-08-15  |  8KB  |  184 lines

  1. ; File......: SAVEATT.ASM
  2. ; Author....: Ted Means
  3. ; Date......: $Date:   15 Aug 1991 23:07:58  $
  4. ; Revision..: $Revision:   1.1  $
  5. ; Log file..: $Logfile:   E:/nanfor/src/saveatt.asv  $
  6. ; This is an original work by Ted Means and is placed in the
  7. ; public domain.
  8. ;
  9. ; Modification history:
  10. ; ---------------------
  11. ;
  12. ; $Log:   E:/nanfor/src/saveatt.asv  $
  13. ;  
  14. ;     Rev 1.1   15 Aug 1991 23:07:58   GLENN
  15. ;  Forest Belt proofread/edited/cleaned up doc
  16. ;  
  17. ;     Rev 1.0   12 Jun 1991 01:30:20   GLENN
  18. ;  Initial revision.
  19. ;
  20.  
  21.  
  22. ;  $DOC$
  23. ;  $FUNCNAME$
  24. ;     FT_SAVEATT()
  25. ;  $CATEGORY$
  26. ;     Video
  27. ;  $ONELINER$
  28. ;     Save the attribute bytes of a specified screen region.
  29. ;  $SYNTAX$
  30. ;     FT_SAVEATT( <nTop>, <nLeft>, <nBottom>, <nRight>  ) -> cAttributes
  31. ;  $ARGUMENTS$
  32. ;     <nTop>, <nLeft>, <nBottom>, and <nRight> define the screen region.
  33. ;  $RETURNS$
  34. ;     A character string containing the screen attribute bytes for the
  35. ;     specified region.  If the memory to store the return value could
  36. ;     not be allocated, the function returns NIL.
  37. ;  $DESCRIPTION$
  38. ;     This function is similar to Clipper's SaveScreen(), except that it only
  39. ;     saves the attribute bytes.  This is useful if you want to change the
  40. ;     screen color without affecting the text.
  41. ;
  42. ;     *** INTERNALS ALERT ***
  43. ;
  44. ;     This function calls the Clipper internal __gtMaxCol to obtain the
  45. ;     maximum column value for the current video mode.  If you're too gutless
  46. ;     to use internals, then this function isn't for you.
  47. ;  $EXAMPLES$
  48. ;     // Save attributes of row 4
  49. ;     cBuffer := FT_SAVEATT( 4, 0, 4, maxcol())
  50. ;
  51. ;     // Save attributes from middle of screen
  52. ;     cBuffer := FT_SAVEATT(10,20,14,59)
  53. ;  $SEEALSO$
  54. ;     FT_RESTATT()
  55. ;  $END$
  56. ;
  57.  
  58.         IDEAL
  59.  
  60. Public   FT_SAVEATT
  61.  
  62. Extrn    __ParNI:Far
  63. Extrn    __gtMaxCol:Far                      ; INTERNAL!!  INTERNAL!!
  64. Extrn    __XAlloc:Far
  65. Extrn    __XFree:Far
  66. Extrn    __RetCLen:Far
  67.  
  68. Upper    EQU       Word Ptr BP - 2
  69. Left     EQU       Word Ptr BP - 4
  70. Lower    EQU       Word Ptr BP - 6
  71. Right    EQU       Word Ptr BP - 8
  72. BufSize  EQU       Word Ptr BP - 10
  73. BufSeg   EQU       Word Ptr BP - 12
  74. BufOfs   EQU       Word Ptr BP - 14
  75. BufPtr   EQU       DWord Ptr BP - 14
  76. MaxCol   EQU       Word Ptr BP - 16
  77.  
  78. Segment  _NanFor   Word      "CODE"
  79.          Assume    CS:_NanFor
  80.  
  81. Proc     FT_SAVEATT          Far
  82.  
  83.          Push      BP                        ; Save BP
  84.          Mov       BP,SP                     ; Set up stack reference
  85.          Sub       SP,16                     ; Allocate space for locals
  86.  
  87.          Call      __gtMaxCol                ; Get current value of maxcol()
  88.          Inc       AX                        ; Set to number of columns
  89.          Mov       [MaxCol],AX               ; Store it in local
  90.  
  91.          Mov       AX,1                      ; Specify param #1
  92.          Push      AX                        ; Put on stack
  93.          Call      __ParNI                   ; Get value
  94.          Mov       [Upper],AX                ; Store in local
  95.  
  96.          Mov       AX,2                      ; Specify param #2
  97.          Push      AX                        ; Put on stack
  98.          Call      __ParNI                   ; Get value
  99.          Mov       [Left],AX                 ; Store in local
  100.  
  101.          Mov       AX,3                      ; Specify param #3
  102.          Push      AX                        ; Put on stack
  103.          Call      __ParNI                   ; Get value
  104.          Mov       [Lower],AX                ; Store in local
  105.          
  106.          Mov       AX,4                      ; Specify param #4
  107.          Push      AX                        ; Put on stack
  108.          Call      __ParNI                   ; Get value
  109.          Mov       [Right],AX                ; Store in local
  110.          Add       SP,8
  111.  
  112.          Mov       AX,[Right]                ; Load right column
  113.          Sub       AX,[Left]                 ; Subtract left
  114.          Inc       AX                        ; Get column count
  115.          Mov       DX,[Lower]                ; Load lower row
  116.          Sub       DX,[Upper]                ; Subtract upper
  117.          Inc       DX                        ; Get row count
  118.          Mul       DX                        ; Calculate buffer size
  119.          Mov       [BufSize],AX              ; Store in local
  120.          Push      AX                        ; Put on stack
  121.          Call      __XAlloc                  ; Allocate buffer
  122.          Add       SP,2                      ; Realign stack
  123.          Mov       [BufSeg],DX               ; Load segment into local
  124.          Mov       [BufOfs],AX               ; Load offset into local
  125.          Or        DX,AX                     ; Check for null pointer
  126.          JZ        Exit                      ; If so, allocation failed
  127.  
  128. SetPtr:  Push      DS                        ; Save appropriate registers and
  129.          Push      SI                        ; make sure direction flag clear
  130.          Push      DI
  131.          CLD
  132.  
  133.          LES       DI,[BufPtr]               ; Load pointer to buffer
  134.          Xor       AX,AX                     ; Clear AX
  135.          Mov       DS,AX                     ; Point DS to low memory
  136.          Mov       AX,0B800h                 ; Initialize video base
  137.          Cmp       [Word Ptr 463h],3B4h      ; Monochrome?
  138.          JNE       SetVid                    ; No, continue
  139.          Mov       AX,0B000h                 ; Set video base to mono
  140.  
  141. SetVid:  Mov       DS,AX                     ; Set video base
  142.          Xor       SI,SI                     ; Start at offset 0
  143.          Mov       CX,[Lower]                ; Get lower row
  144.          Sub       CX,[Upper]                ; Subtract upper row
  145.          Inc       CX                        ; Get number of rows
  146.  
  147. Rows:    Mov       AX,CX                     ; Get row number
  148.          Sub       AX,[Lower]                ; Subtract last row
  149.          Dec       AX                        ; Get negation of row
  150.          Neg       AX                        ; Convert to abs()
  151.          Mul       [MaxCol]                  ; Multiply by column count
  152.          SHL       AX,1                      ; Multiply by two
  153.          Mov       BX,[Left]                 ; Get left column
  154.          SHL       BX,1                      ; Multiply by two
  155.          Inc       BX                        ; Point to attribute byte
  156.          Add       BX,AX                     ; Add rows * columns
  157.          Push      CX                        ; Save row indicator
  158.          Mov       CX,[Right]                ; Load right column
  159.          Sub       CX,[Left]                 ; Subtract left column
  160.          Inc       CX                        ; Get number of columns
  161. Cols:    Mov       AL,[Byte Ptr BX + SI]     ; Load attribute byte
  162.          Stosb                               ; Store in allocated string
  163.          Add       BX,2                      ; Point to next attribute byte
  164.          Loop      Cols                      ; Get next byte
  165.          Pop       CX                        ; Restore row indicator
  166.          Loop      Rows                      ; Do next row
  167.  
  168. Done:    Pop       DI                        ; Restore registers
  169.          Pop       SI
  170.          Pop       DS
  171.          Push      [BufSize]                 ; Put buffer size on stack
  172.          Push      [BufSeg]                  ; Put buffer segment on stack
  173.          Push      [BufOfs]                  ; Put buffer offset on stack
  174.          Call      __RetCLen                 ; Return string to Clipper app
  175.          Call      __XFree                   ; Free memory held by buffer
  176. Exit:    Mov       SP,BP
  177.          Pop       BP
  178.          Ret
  179. Endp     FT_SAVEATT
  180. Ends     _NanFor
  181. End
  182. 
  183.